package com.learn.mq.listener;

import com.learn.mq.beans.Person;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.LocalTransactionState;
import org.apache.rocketmq.client.producer.TransactionListener;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageExt;
import org.springframework.stereotype.Component;

/**
 * ClassName:Listener2Msg
 * Package:com.learn.mq.listener
 * Description:
 *
 * @Author:@郭先森
 * @Create:2025/7/30 - 17:01
 * @Version:v1.0
 */
@Component
@Slf4j
public class Listener2Msg implements TransactionListener {
    @Override
    public LocalTransactionState executeLocalTransaction(Message message, Object o) {
        Person person = (Person) o;
        log.info("事务半消息发送成功，开始执行本地事务...................");
        log.info("收到的参数为："+person);
        log.info("本地事务执行结束！！！");
        return LocalTransactionState.COMMIT_MESSAGE;
    }

    @Override
    public LocalTransactionState checkLocalTransaction(MessageExt messageExt) {
        log.info("回查本地事务是否执行完成..................");
        log.info("本地事务执行完成..................");
        return LocalTransactionState.COMMIT_MESSAGE;
    }
}
